package com.ruoyi.quartz.controller;

import java.time.LocalDateTime;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.enumutil.SysUserEnum;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/sysUserSelect")
public class SySUserSelectController {
    //用户表
    @Resource
    private SysUserMapper sysUserMapper;

    //设置时间
    @PostMapping("/set/NotificationExpireTime")
    public AjaxResult setNotificationExpireTime(String day){
        System.out.println(day);
        //获取用户
        SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
        //设置默认值
        sysUser.setUpdateTime(new Date());
        // 获取当前时间
        Date currentDate = new Date();
        // 使用 Calendar 进行日期计算
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        if("seven".equals(day)){
            calendar.add(Calendar.DAY_OF_YEAR, 7); // 加7天
        }
        if("undefined".equals(day)){
//            calendar.add(Calendar.MINUTE, 2); // 加2分钟 // 加1小时
            calendar.add(Calendar.HOUR_OF_DAY, 1); // 加1小时
        }

        // 获取7天后的时间
        Date newDate = calendar.getTime();
        //设置7天之后提示时间
        sysUser.setNotificationExpireTime(newDate);
        //调用S
        sysUserMapper.updateUser(sysUser);
        AjaxResult ajax = AjaxResult.success("七天内不再提示");
        return ajax;
    }

    //判断用户是否勾选七天提醒
    @PostMapping("/get/NotificationExpireTime")
    public AjaxResult getNotificationExpireTime(){
        //获取用户
        SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
        System.out.println("abc");
        System.out.println(sysUser);
        System.out.println(sysUser.getNotificationExpireTime());

        if(sysUser.getNotificationExpireTime()==null){
            //为null则显示
            return AjaxResult.success(true);
        }else{
            //设置false不需要弹窗,
            Date notificationExpireTime = sysUser.getNotificationExpireTime();
            //比较时间戳(时间大于当前时间就不显示)
            if(notificationExpireTime.getTime() > new Date().getTime()){
                return AjaxResult.success(false);
            }else{
                return AjaxResult.success(true);
            }
        }

    }



}
